import request from "@/utils/request";
const baseUrlV2 = '/api'
const defaultApi = (apiName) => {
    return {
        tree: (params) => request.get(`/${apiName}/tree`, { params }),
        list: (params) => request.get(`/${apiName}/list`, { params }),
        page: (params) => request.get(`/${apiName}`, { params }),
        read: (id) => request.get(`/${apiName}/` + id),
        create: (id, data) => request.post(`/${apiName}`, data),
        update: (id, data) => request.put(`/${apiName}/` + id, { ...data, create_time: undefined, id: undefined }),
        delete: (id) => request.delete(`/${apiName}/` + id)
    }
}
export const http = {
    menu: {
        ...defaultApi('system/menu'),
        list: undefined
    },
    role: {
        ...defaultApi('system/role'),
        roleList: () => request.get('/system/role/simple-list'),
        getRoleMenus: (roleId) => request.get('/system/permission/list-role-menus?roleId=' + roleId),
        updateRoleMenus: (data) => request.post('/system/permission/assign-role-menu', data)
    },
    systemUser: {
        ...defaultApi('system/user'),
        getUserRoles: (userId) => request.get('/system/permission/list-user-roles?userId=' + userId),
        updateUserRoles: (data) => request.post('/system/permission/assign-user-role', data)
    },
    login: (data) => request.post('/system/auth/login', data),
    getUserInfo: () => request.get('/system/auth/get-permission-info'),

    banner: {
        ...defaultApi('banner')
    },
    cdk: {
        ...defaultApi('cdk'),
        batchCreate: (data) => request.post(`/cdk/batchCreate`, data)
    },
    news: {
        ...defaultApi('news')
    },
    newsCategory: {
        ...defaultApi('newsCategory')
    },
    product: {
        ...defaultApi('product')
    },
    productCategory: {
        ...defaultApi('productCategory')
    },
    productItem: {
        ...defaultApi('productItem')
    },
    file: {
        ...defaultApi('file')
    },
    user: {
        ...defaultApi('user'),
        getUserQrCode: (data) => request.get(`/user/wx/getUserQrCode`, { params: data })
    },
    order: {
        ...defaultApi('order'),
        refund: (data) => request.post(`/order/refund`, data),
        refundConfirm: (data) => request.post(`/order/refund/confirm`, data)
    },
    orderCode: {
       ...defaultApi('orderCode'),
        verify: (data) => request.post(`/orderCode/verify`, data)
    },
    userProduct: {
        ...defaultApi('userProduct')
    },
    ticketShop: {
        ...defaultApi('ticketShop')
    },
    ticketLine: {
        ...defaultApi('ticketLine')
    },
    distribution: {
        ...defaultApi('distribution')
    },
    balanceRecord: {
        ...defaultApi('balanceRecord')
    },
    coupon: {
        ...defaultApi('coupon'),
        distribute: (data) => request.post(`/coupon/distribute`, data)
    },
    userCoupon: {
        ...defaultApi('userCoupon')
    },
    post: {
        ...defaultApi('post')
    },
    postComment: {
       ...defaultApi('postComment')
    }
}
// uploadFile
export const uploadFile = (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/upload/file',
        method: 'post',
        data: formData
    })
}
